package cn.wh.context.support;

import cn.wh.beans.BeansException;
import cn.wh.beans.factory.ConfigurableListableBeanFactory;
import cn.wh.beans.factory.support.DefaultListableBeanFactory;

/**
 * @Author wanghao
 * @Date 2022-09-20 22:28
 * @Description: TODO
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {
    private DefaultListableBeanFactory beanFactory;


    @Override
    protected void refreshBeanFactory() throws BeansException {
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }


    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);


    private DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory();
    }

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }


}
